/**
 * 公用的首页头部
 * @returns {*|jQuery|HTMLElement}
 */
function getIndexHead() {

    const $widget = $(`<div class="header clearfix"></div>`);

    getCurrUserInfo(({Code, Message, Result}) => {
        if (Code !== 10000) {
            return location.href = "/admin/login.html?" + $.param({
                msg: Message,
                back: location.href
            });
        }

        const {userId, userName, phone, email, avatarUrl} = Result;
        $widget.append(`
            <a href="${$.sUrl("/admin/index.html")}">
                <img src="/ui/pc/images/logo2.png" class="head-logo" alt="">
            </a>
            <div class="header-r clearfix">
                <a href="javascript:;" class="header-link c-hide" data-widget="notice">
                    <i class="iconfont icon-xiaoxi"></i>
                    <i class="header-num"></i>
                </a>
                
                <div class="head-memb" style="z-index: 9999">
                    <div class="head-memb-i">
                        <img src="${avatarUrl || "/ui/pc/images/doc-m.png"}" class="head-img"  alt=""/>${userName}<i class="bi-chevron-down"></i>
                    </div>
                    <div class="head-doc-info c-hide">
                        <div class="hos-info clearfix">
                            <img class="doc-info-logo" src="${avatarUrl || "/ui/pc/images/doc-m.png"}"  alt="">
                            <div class="">
                                <p class="index-hos-tit">${userName}</p>
                                <p class="index-admin">${email || ''}<i></i></p>
                                <p>${phone || ''}</p>
                            </div>
                        </div>
                        <div class="index-hos-btn clearfix">
                            <a href="javascript:" data-btn="settingBtn"><i class="bi-nut mr-10 c-f18"></i>账号设置</a>
                            <a href="javascript:" data-btn="logoutBtn"><i class="bi-box-arrow-in-right mr-10 c-f18"></i>退出登录</a>
                        </div>
                    </div>
                </div>
                
            </div>
        `)

        const $userInfoWidget = $widget.find('.head-doc-info')
        $widget.find('.head-memb,.head-doc-info').on('mouseover', function () {
            $userInfoWidget.removeClass('c-hide')
        }).on('mouseout', function () {
            $userInfoWidget.addClass('c-hide')
        })


        $widget.find('[data-btn="settingBtn"]').on("click", () => {
            location.href = $.sUrl("/admin/account.html");
        })

        $widget.find('[data-btn="logoutBtn"]').on("click", () => {
            logout(() => {
                location.href = "/admin/login.html";
            });
        })


    })

    return $widget;

    function logout(callback = Function()) {
        $.sApi({
            url: "/Login/logout"
        }, callback)
    }

    function getCurrUserInfo(callback = Function()) {
        $.sApi({
            loading: false,
            url: "/Login/getCurrUserInfo"
        }, callback)
    }

}